package com.sunkingdom.demo;

import com.jcabi.aspects.Loggable;
import com.sunkingdom.qq.user.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RunWith(value= SpringJUnit4ClassRunner.class)
@ContextConfiguration(value="/WEB-INF/dispatcher-servlet.xml")
@ActiveProfiles("test")
public class HelloWorld {

    @Autowired
    private SqlSession sqlSession;

    @Test
    @Transactional
    @Loggable
    public void selectUsersTest(){
        List<User> users = sqlSession
                .selectList("com.sunkingdom.qq.mapper.UserMapper.selectUsers");
        for(User user : users){
            System.out.println("user: " + user.getUserId() + ", " + user.getUsername() + ", " + user.getPassword());
        }
    }
}
